package cn.itcast.zt.java8.thread;

import cn.hutool.core.lang.Console;
import cn.hutool.core.thread.ConcurrencyTester;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.HttpUtil;
import org.junit.Test;

/**
 * 高并发测试
 */
public class ConcurrencyTesterDemo {
    @Test
    public void highConcurrencyTest() {
            ConcurrencyTester tester = ThreadUtil.concurrencyTest(10, () -> {
                for (int i = 0; i < 10; i++) {
                    // 测试的逻辑内容
                    long start = System.currentTimeMillis();
                    try {
                        HttpUtil.get("http://127.0.0.1:18080/eosBillCollStandard/multiThreadUsageData", 3000);
                    }catch (Exception e) {
                        e.printStackTrace();
                    }
                    //Console.log("{} test finished, delay: {}", Thread.currentThread().getName(), System.currentTimeMillis() - start);
                }
            });


        // 获取总的执行时间，单位毫秒
        Console.log(tester.getInterval());
    }
}
